﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAPbobsCOM;

namespace CompanySyncProject
{
    public class MarketingDoc: BaseRun
    {
        public MarketingDoc(Company co, System.IO.StreamWriter lo)
            : base(co, lo)
        {

        }

        public override void Run()
        {
            Documents order = oCompany.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
            order.CardCode = "3E";

            order.Lines.ItemCode = "IA-0002";
            order.Lines.Quantity = 10;


            //order.Lines.BaseEntry = 1;
            //order.Lines.BaseLine = 1;
            //order.Lines.BaseType = System.Convert.ToInt32(BoObjectTypes.oPurchaseQuotations);
            //order.Lines.Price = 45;
            //order.Lines.Add();
            /*
            order.Lines.BaseEntry = 1;
            order.Lines.BaseLine = 3;
            order.Lines.BaseType = System.Convert.ToInt32(BoObjectTypes.oPurchaseQuotations);
            order.Lines.TaxCode = "J2";
            order.Lines.Add();
            */
           
            int ret = order.Add();
            if (ret == 0)
            {
                Documents order2 = oCompany.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
                bool rt = order2.GetByKey(4);
                order2.Lines.Add();
                order2.Lines.BaseEntry = 1;
                order2.Lines.BaseLine = 2;
                order2.Lines.BaseType = System.Convert.ToInt32(BoObjectTypes.oPurchaseQuotations);
                //order2.Lines.ItemCode = "IA-000103";
                order2.Lines.Add();
                //order2.Lines.SetCurrentLine(2);
                //order2.Lines.Delete();

                int ret2 = order2.Update();
                if (ret2 != 0)
                {
                    string msg;
                    oCompany.GetLastError(out ret, out msg);
                    System.Console.WriteLine(msg);
                }

                System.Console.WriteLine("successfully!");
            }
            else
            {
                string msg;
                oCompany.GetLastError(out ret, out msg);
                System.Console.WriteLine(msg);
            }
        }
    }
}
